//请求基础路径
const baseURL = 'http://nocat.life:3017';

const request = async (url : string, method : any, data : any, isLoading = true) => {
	//显示 loading 提示框
	if (isLoading) {
		uni.showLoading({ title: '加载中' });
	};
	const res = await uni.request({
		url: baseURL + url,
		method,
		data,
		timeout: 3000,
		header: {
			Authorization: uni.getStorageSync('login_token')
		}
	});
	//关闭 loading 提示框
	uni.hideLoading();
	return res.data;
}

export function httpGet(url : string, data ?: any, isLoading = true) {
	return request(url, 'GET', data, isLoading);
};
export function httpPut(url : string, data : any, isLoading = true) {
	return request(url, 'PUT', data, isLoading);
};
export function httpPost(url : string, data : any, isLoading = true) {
	return request(url, 'Post', data, isLoading);
};
export function httpDelete(url : string, data : any, isLoading = true) {
	return request(url, 'DELETE', data, isLoading);
};